package com.ant.time.line.activities.adapters;

import android.databinding.DataBindingUtil;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.ant.time.line.R;
import com.ant.time.line.beans.TimeLIneItemBean;
import com.ant.time.line.databinding.ItemTimeLineLayoutBinding;

import java.util.List;

/**
 * Created with AS
 * User: Ant
 * Date: 2018/10/7
 * Time: 14:19
 * Name: TimeListAdapter
 * Description:
 *
 * @author Ant
 * @version 1.0.0
 */
public class TimeListAdapter extends BaseAdapter {
    private List<TimeLIneItemBean> data;

    public void setData(List<TimeLIneItemBean> data) {
        this.data = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return data == null ? 0 : data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ItemTimeLineLayoutBinding binding = null;

        if (convertView == null) {
            binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
                    R.layout.item_time_line_layout, parent, false);
            convertView = binding.getRoot();
            convertView.setTag(binding);
        } else {
            binding = (ItemTimeLineLayoutBinding) convertView.getTag();
        }

        //view 在这里处理不同的右边view来显示

        //data
        TimeLIneItemBean bean = data.get(position);
        binding.itemTimeLine.setText(bean.getTimeStr());
        binding.itemTimeLine.setType(bean.getType());

        return convertView;
    }
}
